1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
@RunWith(SpringRunner.class) @SpringBootTest public class CodeTest {
@Autowired private SqlSessionFactory sqlSessionFactory;
@Autowired private BeetlGroupUtilConfiguration beetlConfig;
@Autowired private CodeFactory codeFactory;
@Value("${project.base-path:#{null}}") private String basePath;
@Test public void codeGeneratorTest() throws SQLException{
String rootPackage = "aaa.bbb.ccc"; GroupTemplate gt = beetlConfig.getGroupTemplate(); SqlSession sqlSession = sqlSessionFactory.openSession(); Map<String, Map<String, String>> databaseAttribute = DBUtil.getDatabaseAttribute(sqlSession);
String databaseName = sqlSession.getConnection().getMetaData().getDatabaseProductName(); databaseAttribute.forEach((tableName,columnMap)->{ List<Column> columnList = new ArrayList<>(); columnMap.forEach((name,type)->{ String javaType = null; if("MySQL".equals(databaseName)){ javaType = DBUtil.sqlTypeToJavaType(type); }else if("Oracle".equals(databaseName)){ javaType = DBUtil.oracleSqlTypeToJavaType(type); } columnList.add(new Column(name, javaType, StringUtil.mapUnderscoreToCamelCase(name), StringUtil.mapTableNameToClassName(name))); }); TplProperties properties = null; if(basePath != null){ properties = new TplProperties(basePath,rootPackage,tableName,columnList); }else{ properties = new TplProperties(rootPackage,tableName,columnList); }
try { codeFactory.getCodeInstance("CONTROLLER").create(gt,properties,"/Controller.tpl"); codeFactory.getCodeInstance("SERVICE").create(gt,properties,"/Service.tpl"); codeFactory.getCodeInstance("ENTITY").create(gt,properties,"/Entity.tpl"); codeFactory.getCodeInstance("MAPPER").create(gt,properties,"/Mapper.tpl"); codeFactory.getCodeInstance("MAPPER_XML").create(gt,properties,"/MapperXml.tpl"); } catch (IOException e) { e.printStackTrace(); } });
} }
|